<template>
  <DatePicker 
    ref="dateTime"
    style="width: 320px"
    @on-change="onSelectTime"
    :disabled="disabled"
    :options="options"
    placeholder="开始时间"
    type="datetimerange"
    format="yyyy-MM-dd HH:mm:ss"
    v-model="DateValue">
  </DatePicker>
</template>
<script>
  import { formatDate } from '@/util'
  export default {
    props: {
      DateValue: '',
      disabled: ''
    },
    data() {
      return {
        value: '',
        options: {
          disabledDate(date) {
            return date && date.valueOf() < Date.now() - 86400000;
          }
        }
      }
    },
    methods: {
      onSelectTime(res, type) {
        let newDate = []
        if(res[0] !== '' &&  res[1] !== ''){
          if(type !== 'time') {
            newDate.push(formatDate(res[0]) + ' 00:00:00')
            newDate.push(formatDate(res[1]) + ' 23:59:59')
          }
          if(type == 'time') {
            newDate.push(new Date(res[0]))
            newDate.push(new Date(res[1]))
          }
        }
        this.$emit('input', newDate)
        // this.$refs['dateTime'].onSelectionModeChange('time')
      }
    },
    watch: {
      // DateValue(val) {
      //   this.DateValue = val
      // }
    }
  }
</script>